<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>网络笔记分享页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" href="${pageContext.servletContext.contextPath}/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.servletContext.contextPath}/static/css/global.css">
    <script src="${pageContext.servletContext.contextPath}/layui/layui.js"></script>
    <script src="${pageContext.servletContext.contextPath}/static/js/jquery-3.2.1.js"></script>
    <style type="text/css">
        .linear{
            background-image: linear-gradient(to right, #eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%);
        }
    </style>
</head>
<body class="linear">
<%--公共头部开始--%>
<jsp:include page="/WEB-INF/jsp/common/head.jsp"></jsp:include>
<%--公共头部结束--%>

<div class="main layui-clear">
    <div class="wrap">
        <div class="content" style="margin-right:0">
            <div class="fly-tab">
                <form action="${pageContext.servletContext.contextPath}/shareindex" method="post" class="fly-search">
<%--                    <i class="iconfont icon-sousuo"></i>--%>
<%--                    <input class="layui-input" autocomplete="off" placeholder="搜索内容" type="text" value="${title}" name="title">--%>
                </form>
                <%--屏蔽a标签的默认跳转--%>
<%--                <a href="javascript:;" onclick="" class="layui-btn jie-add">测试按钮</a>--%>
            </div>

            <c:if test="${pageInfo.list != null}">
                <ul class="fly-list">
                    <c:forEach items="${pageInfo.list}" var="note">
                        <li class="fly-list-li">
                            <a href="javascript:;" class="fly-list-avatar">
                                <img src="${pageContext.servletContext.contextPath}/${note.avatar}" alt="">
                            </a>
                            <h2 class="fly-tip">
                                <a href="${pageContext.servletContext.contextPath}/note/detail?id=${note.id}">${note.title}</a>
                            </h2>
                            <p>
                                <span><a href="">${note.loginname}</a></span>
                                <span><fmt:formatDate value="${note.createtime}" pattern="yyyy-MM-dd HH:mm:ss" /></span>
                                <span class="jieda-zan zanok" type="zan" id="zan" name="zan" onclick="zan('${note.id}')">
											<i class="iconfont icon-zan"></i><em id="" name="">${note.likes}</em>
										</span>
                                <span class="jieda-zan zanok">
                                          <i class="iconfont" title="评论">&#xe60c;</i> ${note.talks}
                                        </span>
                            </p>
                        </li>
                    </c:forEach>
                </ul>
            </c:if>

            <c:if test="${pageInfo.list == null}">
                <div class="fly-none">并无相关数据</div>
            </c:if>
            <input type="hidden" id="pn" name="pn" value="${pageInfo.pageNum}">
            <div style="text-align: center">
                <div class="laypage-main"><%--<span class="laypage-curr">1</span>--%>
                    <c:if test="${pageInfo.pageNum ne 1}">
                        <a href="${pageContext.servletContext.contextPath}/shareindex?pn=${pageInfo.pageNum - 1}" class="laypage-next">上一页</a>
                    </c:if>
                    <a href="${pageContext.servletContext.contextPath}/shareindex?pn=1" class="laypage-last" title="首页">首页</a>
                    <c:forEach begin="1" end="${size }" var="page">
                        <a href="${pageContext.servletContext.contextPath}/shareindex?pn=${page }">${page }</a>
                    </c:forEach>
                    <%--<span>…</span>--%>
                    <a href="${pageContext.servletContext.contextPath}/shareindex?pn=${size }" class="laypage-last" title="尾页">尾页</a>
                    <c:if test="${pageInfo.pageNum ne pageInfo.pages}">
                        <a href="${pageContext.servletContext.contextPath}/shareindex?pn=${pageInfo.pageNum + 1}" class="laypage-next">下一页</a>
                    </c:if>
                </div>
            </div>

        </div>
    </div>
</div>
</body>
<script>
    /*发布问题*/
    function publish() {
        //从session域中获取user对象
        var user = "${user}";
        //判断user对象是否为空
        if(user == "") {
            alert("请先登录！");
        } else {
            window.location.href = "${pageContext.servletContext.contextPath}/ques/form";
        }
    }

    function zan(id) {
        var pn=$("#pn").val();
        $.ajax({
            url :  "${pageContext.servletContext.contextPath}/note/zan",
            data:{"noteid":id},
            type : "post",
            success : function (likes) {
                //console.log(likes);
                //$(".em").html(likes);
                window.location.href = "${pageContext.servletContext.contextPath}/shareindex?pn="+pn;
            }
        });
    }
</script>
</html>